#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;
bool is_prime(int x)
{
	for (int i = 2; i <= sqrt(x); i++)
	{
		if (x % i == 0) return false;
	}
	return true;
}
bool is_huiwen(int x)
{
	string s1 = to_string(x);
	string s2 = s1;
	reverse(s1.begin(),s1.end());
	if (s1 == s2) return true;
	else return false;
}
int main()
{
	int n, m;cin >> n >> m;
	int count = 0;
	for (int i = n; i <= m; i++)
	{
		if (is_prime(i) && is_huiwen(i))
		{
			printf("%d ", i);
			count++;
			if (count % 5 == 0) printf("\n");
		}
	}
	return 0;
}